<?php
/**
 * 
 * @todo description of this class
 * 
 * @author Alton Crossley <crossleyframework@nogahidebootstrap.com>
 * @package Crossley Framework
 *  
 * @copyright Copyright (c) 2003-2009, Nogaide BootStrap INC. All rights reserved.
 * @license BSD http://opensource.org/licenses/bsd-license.php
 * @version $Id:$
 * 
 */
class X_Filter_HtmlEntities implements X_Filter_Interface
{
    /**
     * lets you define what will be done with 'single' and "double" quotes.
     *
     * @var ENT_COMPAT
     */
    public $cQuoteStyle = ENT_COMPAT;
    /**
     * defines character set used in conversion
     *
     * @var string
     */
    public $sCharset;
    /**
     * encode existing html entities
     *
     * @var bool
     */
    public $bDoubleEncode;
    
    /**
     * Sets default option values for this instance
     *
     * @param  boolean $allowWhiteSpace
     * @return void
     */
    public function __construct($cQuoteStyle = ENT_QUOTES, $sCharset = 'ISO-8859-15', $bDoubleEncode = true)
    {
        $this->cQuoteStyle = $cQuoteStyle;
        $this->sCharset = $sCharset;
        $this->bDoubleEncode = $bDoubleEncode;
    }
    
    /**
     * @see X_Filter_Abstract::filter()
     *
     * @param unknown_type $sValue
     * @return string
     */
    public function filter($sValue)
    {
       return htmlentities($sValue, $this->cQuoteStyle, $this->sCharset, $this->bDoubleEncode); 
    }

    static function go($xValue, $cQuoteStyle = ENT_QUOTES, $sCharset = 'ISO-8859-15', $bDoubleEncode = true)
    {
        $sSelf = __CLASS__;
        $oFileter = new $sSelf($cQuoteStyle, $sCharset, $bDoubleEncode);
        
        if (is_array($xValue))
        {
            $aFiltered = array();
            foreach ($xValue as $sKey => $xValue)
            {
                $aFiltered[$sKey] = $oFileter->filter((string)$xValue);
            }
            return $aFiltered;
        }
        else
        {
            return $oFileter->filter((string)$xValue);
        }
        
    }
}
